package com.woniuxy.service.impl;

/**
 * @Author: 马宇航
 * @Todo: 查看线程可见性问题
 * @DateTime: 25/08/05/星期二 14:12
 * @Component: 成都蜗牛学苑
 **/
public class ThreadVolatile {
    static boolean flag = true;

    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            while (flag){
            }
            System.out.println("A线程执行完成。");
        },"A").start();
        //确保A线程先执行，进入到循环里面
        Thread.sleep(20);
        new Thread(()->{
            flag = false;
        }).start();
        System.out.println("AB线程已启动");
    }
}
